<extend name="Base/common"/>
<block name="style">
    <style type="text/css">
        .weui-cell_access .weui-cell__ftnone:after{border-style:none;}
    </style>
</block>
<block name="body">
    <php>
        $PROVINCE =   C('PROVINCE');
    </php>
    <php>
        if(!empty($info)&&!empty($realname)){
            if($info['openbank']==10||$info['openbank']==13||$info['openbank']==15||$info['openbank']==16||$info['openbank']==17||$info['openbank']==18||$info['openbank']==19||$info['openbank']==20){
                 $info['openbank_num']='999';
            }else{
                $info['openbank_num']=$info['openbank'];
            }

    </php>

        <div style="margin:auto;margin-top:3%;width:94%;height:18%;background-image:url('__IMG__/{$info['openbank_num']}.png'); background-repeat:no-repeat; background-size:100% 100%;-moz-background-size:100% 100%;position:relative;">
            <php>
                $OPEN_BANK =   C('OPEN_BANK');
            </php>
            <foreach name="OPEN_BANK" item="val" key="key">
                <if condition="$key eq $info['openbank']"><p style="font-size:16px;color:#fff;height:20px;line-height:55px;margin-left:20%;">{$val}</p>
                </if>
            </foreach>

                <p style="font-size:12px;color:#fff;height:20px;line-height:55px;margin-left:20%;">储蓄卡</p>
                <input type="hidden" id="card_number" value="{$info['card_number']}">
                <php>
                    $info['card_number']=substr($info['card_number'],count($info['card_number'])-4);
                </php>
                <p style="font-size:20px;color:#fff;height:25px;line-height:55px;margin-left:20%;">**** **** **** {$info['card_number']}</p>

                <button type="button" id="jiechu" style="position:absolute;right:7%;top:15%;color:#cacaca;font-size:15px;background:none;border:none">解除绑定</button>
            
        </div>

    <php>
        }else{
    </php>
    <form class="formtijiao" action="{:U('')}" method="post">
        <div class="weui-cells weui-cells_form">
            <div class="weui-cell ">
                <div class="weui-cell__hd"><label class="weui-label">开户银行</label></div>
                <div class="weui-cell__bd">
                    <div class="weui-cell weui-cell_select">
                        <div class="weui-cell__bd">
                    <php>
                        $OPEN_BANK =   C('OPEN_BANK');
                    </php>
                    <select class="weui-select" name="openbank">
                        <foreach name="OPEN_BANK" item="val" key="key">
                            <option <eq name="key" value="$info['openbank']">selected="selected"</eq> value="{$key}">{$val}</option>
                        </foreach>
                    </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="weui-cell province_select">
                <div class="weui-cell__hd"><label class="weui-label">开户省份</label></div>
                <div class="weui-cell__bd">
                    <div class="weui-cell weui-cell_select">
                        <input type="hidden" value="{$info.province}" class="province" name="province" >
                        <div class="weui-cell__bd province_text">
                            <empty name="info['province']">
                                请选择
                                <else/>
                                {$PROVINCE[$info[province]]}
                            </empty>

                        </div>
                    </div>
                </div>

            </div>
            <div class="weui-cell city_select">
                <div class="weui-cell__hd"><label class="weui-label">开户城市</label></div>


                <div class="weui-cell__bd">
                    <div class="weui-cell weui-cell_select">
                        <input type="hidden" value="{$info.city}" class="city" name="city" >
                        <div class="weui-cell__bd city_text">
                            <empty name="info['city']">
                                请选择
                                <else/>
                                <php>
                                    $data   =   D('Area')->get_addr($info['city']);echo ($data);
                                </php>
                            </empty>
                        </div>
                    </div>
                </div>

            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">开户支行</label></div>
                <div class="weui-cell__bd">
                    <input type="text" name="subbranch" value="{$info.subbranch}"  placeholder="请输入银行开户支行" class="weui-input subbranch">
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">开户名字</label></div>
                <div class="weui-cell__bd">
                    {$realname}<input type="hidden" name="name" value="{$realname}">
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">银行卡号</label></div>
                <div class="weui-cell__bd">
                   <input type="number" pattern="[0-9]*" placeholder="请输入银行卡号" name="card_number" value="{$info.card_number}" class="weui-input card_number">
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">预留号码</label></div>
                <div class="weui-cell__bd">
                    <input name="mobile" type="tel" value="{$info.mobile}" placeholder="请输入银行预留手机号码" class="weui-input mobile">
                </div>
            </div>
        </div>
        <empty name="info">
        <div class="page__bd page__bd_spacing" style="padding-top: 0.5em;">
            <button class="login-btn tijiao"  type="button">确定</button>
        </div>
            <else/>
            <div class="page__bd page__bd_spacing" style="padding-top: 0.5em;">
                <button class="weui-btn weui-btn_primary" onclick="javascript:popup.alert('您无权操作，如信息有误，请联系客服');return false;" style="background-color: #999;" type="button">确定</button>
            </div>
        </empty>
    </form>
        <p class="login-tips">
            <em> &nbsp;&nbsp;&nbsp;&nbsp;温馨提示</em>：
            <br> &nbsp;&nbsp;&nbsp;&nbsp;1、认证成功后无法修改，必须是本人姓名银行卡；
            <br> &nbsp;&nbsp;&nbsp;&nbsp;2、银行卡不正确者，无法进行下一步贷款；
            <br> &nbsp;&nbsp;&nbsp;&nbsp;3、如果银行卡有误，请联系客服修改!
        </p>

    <php>
        }
    </php>
    <php>
        $province = array();
        foreach($PROVINCE as $k=>$v){
        $province[]=['label'=>$v,'value'=>$k];
        }
    </php>
</block>
<block name="script">
    <script type="text/javascript" src="https://wap.lianlianpay.com/lib/llpay.min.js" charset="utf-8"></script>
    <script >

        var province,Url;
        province = <php>echo json_encode($province)</php>;
        Url      = "{:U('Ajax/getRegion')}";
        Zepto(function($){
            $('.province_select').on('click', function () {
                weui.picker(province, {
                    onChange: function (result) {
                    },
                    onConfirm: function (result) {
                        for (var i=0;i<province.length;i++){
                            if(province[i].value==result){
                                $('.province_text').html(province[i].label);
                                $('.province').val(result);
                            }
                        }
                    }
                });
            });
            $('.city_select').on('click', function () {
                var reside_province = $('.province').val();
                if(reside_province=='' || reside_province==0){
                    popup.alert('请选择开户省份');return false;
                }
                AjaxGet(Url,{pid:reside_province},function(data){

                    weui.picker(data, {
                        onChange: function (result) {
                        },
                        onConfirm: function (result) {
                            for (var i=0;i<data.length;i++){
                                if(data[i].value==result){
                                    $('.city_text').html(data[i].label);
                                    $('.city').val(result);
                                }
                            }
                        }
                    });
                });
            });

            //提交表单
            $('.tijiao').click(function(){
                var province,city,subbranch,name,card_number,mobile;
                province    = $('.province').val();
                city        = $('.city').val();
                subbranch   = $('.subbranch').val();
                name        = $('.name').val();
                card_number = $('.card_number').val();
                mobile      = $('.mobile').val();

                if(province==0){
                    popup.alert('请选择开户省份');return false;
                }
                if(city==0){
                    popup.alert('请选择开户城市');return false;
                }
                if(subbranch==''){
                    popup.alert('请输入开户支行');return false;
                }
                if(name==''){
                    popup.alert('请输入开户名字');return false;
                }
                if(card_number==''){
                    popup.alert('请输入银行卡号');return false;
                }

                var datas=$('.formtijiao').serializeArray();
                
                $.ajax({
                    type:'post',
                    url:"{:U('yinhang')}",
                    data:datas,
                    async:false,
                    // dataType:'json',
                    success:function(m){
                        if(m.status==true){
                            //stringifier 函数的作用跟 parse 相反， 用来将一个js对象转换为 JSON 文本。
                            new LLPay().setData(JSON.stringify(m.info)).signReq(function(data){
                                // popup.alert(data.ret_code+'//////'+data.ret_msg)
                                if(data.ret_code =='0000'){
                                    var datas=m.data;
                                    datas['no_agree']=data.no_agree;
                                    $.ajax({
                                        type:'post',
                                        url:"{:U('yinhang2')}",
                                        async:false,
                                        data:datas,
                                        // dataType:'json',
                                        success:function(m){
                                            if(m==1){
                                                confirm('恭喜您，绑卡成功！');
                                                setTimeout(location.href="{:U('mobile')}",1000);
                                                
                                            }else{
                                                popup.alert('未知错误，无法绑定银行卡')
                                            }
                                            
                                        }
                                    });
                                    

                                }else{
                                    popup.alert(data.ret_msg);
                                }
                                
                            });
                        }else{
                            popup.alert(m.info)
                        }
                    }
                });
            }) ;
        });

    $('#jiechu').click(function(){
        var card_number=$('#card_number').val();
        $.ajax({
            type:'post',
            url:"{:U('bankcardunbind')}",
            data:{'card_number':card_number},
            dataType:'json',
            success:function(m){
                confirm(m.info);
                setTimeout(location.reload(),1000);
                
            }
        });
    });

    </script>

</block>